package com.github.thinwonton.springboot.showcase.jdbc.service;

import com.github.thinwonton.springboot.showcase.jdbc.dao.AccountDao;
import com.github.thinwonton.springboot.showcase.jdbc.domain.Account;
import com.github.thinwonton.springboot.showcase.jdbc.exception.BizException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AccountService {
    @Autowired
    private AccountDao accountDao;

    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void saveAccount(Account account) throws BizException {
        int result = accountDao.insert(account);
        if (result <= 0) {
            throw new BizException();
        }
    }

}
